﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "DebugMessage.h"
#include "GbmpNew.h"

#define GNUF_IMPL_CLASS(ClassName)  ClassName##Impl
#define GNUF_IMPL_CTOR(ClassName)   GNUF_IMPL_CLASS(ClassName)::GNUF_IMPL_CLASS(ClassName)
#define GNUF_IMPL_DTOR(ClassName)   GNUF_IMPL_CLASS(ClassName)::~GNUF_IMPL_CLASS(ClassName)
#define GNUF_IMPL_INTERFACE         m_pItf

#define GNUF_IMPL_USE(ClassName) \
    public: \
        typedef impl::GNUF_IMPL_CLASS(ClassName) Impl; \
        ClassName##::Impl * impl() { \
            DBG_WARN_AND_RETURN_NULLPTR_UNLESS(nullptr != m_opImpl.get(), L"Null m_opImpl!", L"GMEP", L"2022-04-17"); \
            return m_opImpl.get(); \
        } \
        const ClassName##::Impl * impl() const { \
            DBG_WARN_AND_RETURN_NULLPTR_UNLESS(nullptr != m_opImpl.get(), L"Null m_opImpl!", L"GMEP", L"2022-04-17"); \
            return m_opImpl.get(); \
        } \
    private: \
        gcmp::OwnerPtr< ClassName##::Impl > m_opImpl;

#define GNUF_IMPL_USED_BY(ClassName) \
        friend class ClassName; \
    public: \
        ClassName * itf() { \
            DBG_WARN_AND_RETURN_NULLPTR_UNLESS(nullptr != m_pItf, L"Null m_pItf!", L"GMEP", L"2022-04-19"); \
            return m_pItf; \
        } \
        const ClassName * itf() const { \
            DBG_WARN_AND_RETURN_NULLPTR_UNLESS(nullptr != m_pItf, L"Null m_pItf!", L"GMEP", L"2022-04-19"); \
            return m_pItf; \
        } \
    private: \
        ClassName * m_pItf = nullptr;

#define GNUF_IMPL_NEW(ClassName, ...) \
    m_opImpl = NEW_AS_OWNER_PTR(ClassName##::Impl, __VA_ARGS__); \
    DBG_WARN_UNLESS(nullptr != m_opImpl.get(), L"Null m_opImpl!", L"GMEP", L"2022-04-17");